<template>
  <div class="login">
    <div class="leftView">
      <div class="textAlignCenter marginBottom40">
        <img src="@/assets/logo/logo-title.png" alt="" width="215" height="42">
      </div>
      <h3 class="title">上海市注册会计师行业</h3>
      <h3 class="title">鉴证业务报告防伪系统</h3>
      <el-form ref="loginForm"
               :model="loginForm"
               :rules="loginRules"
               :label-position="labelPosition"
               class="login-form">
        <el-form-item prop="username" label="账号">
          <el-input v-model="loginForm.username" type="text" auto-complete="off" placeholder="账号" />
        </el-form-item>
        <el-form-item prop="password" label="密码">
          <el-input
            v-model="loginForm.password"
            type="password"
            auto-complete="off"
            placeholder="密码"
            @keyup.enter.native="handleLogin"
          />
        </el-form-item>
        <el-form-item prop="caPwd" label="CA 密码">
          <el-input
            v-model="loginForm.caPwd"
            type="password"
            auto-complete="off"
            placeholder="-- 请插入 CA 证书后重新刷新页面 --"
          />
        </el-form-item>
          <!--        滑块验证-->
        <el-form-item prop="slideStatus" label="验证码">
          <JcRange :successFun="slideSuccess" :errorFun="slideError" />
        </el-form-item>
       <!-- <el-form-item prop="code">
          <el-input
            v-model="loginForm.code"
            auto-complete="off"
            placeholder="验证码"
            style="width: 63%"
            @keyup.enter.native="handleLogin"
          />
          <div class="login-code">
            <img :src="codeUrl" @click="getCode" class="login-code-img"/>
          </div>
        </el-form-item>-->

        <el-form-item style="width:100%;">
          <el-button
            :loading="loading"
            size="medium"
            type="primary"
            style="width:100%;"
            @click.native.prevent="handleLogin"
          >
            <span v-if="!loading">登 录</span>
            <span v-else>登 录 中...</span>
          </el-button>
        </el-form-item>
        <div class="flexRowBetween marginBottom20">
          <el-checkbox v-model="loginForm.rememberMe" class="fontWeight400 colorLink">保持登录状态</el-checkbox>
          <router-link :to="{ path: '/forget' }" class="fontSize14 colorLink">忘记密码？</router-link>
        </div>
      </el-form>
      <!--  底部  -->
      <div class="el-login-footer">
        <span>外省市事务所申请？<router-link :to="{ path: '/register' }" class="fontSize12 colorLink">注册用户？</router-link></span>
        <div style="margin-top:10px;"> <span style="color:red"> * </span> 数字认证服务<a target="_blank" href="https://www.sheca.com/resources/tools" style="color: #5B79E7;" class="fontSize12 colorLink">协卡助手下载</a></div>
        <div style="margin-top:10px;"> <span style="color:red"> * </span> 本系统建议运行在以下浏览器：chrome（谷歌）浏览器、firefox（火狐）浏览器、360浏览器极速模式。使用不兼容的浏览器可能导致浏览异常（如IE浏览器、360浏览器兼容模式）</div>
      </div>
    </div>

  </div>
</template>

<script>
import { getCodeImg } from "@/api/login";
import { getCaCode } from "@/api/ca";
import Cookies from "js-cookie";
import { encrypt, decrypt } from '@/utils/jsencrypt'
import JcRange from '@/components/SliderVerify'
import {getDate,datedifference,handelCaTime} from '@/utils/ruoyi'

export default {
  name: "Login",
  components: { JcRange },
  data() {
    let validateSlide = (rule, value, callback) => {
      let self = this;
      if (self.loginForm.slideStatus !== true) {
        callback(new Error('请向右滑动验证'));
      } else {
        callback();
      }
    };
    return {
      codeUrl: "",
      cookiePassword: "",
      labelPosition: "top",
      caPlaintext: "",
      certificate:{},
      usbKey:{},
      loginForm: {
        username: "",
        password: "",
        rememberMe: false,
        slideStatus: false, // 滑块验证 成功：true，失败：false
        // code: "",
        uuid: "",
        caPws: "",
        caSign: "",
        onlyDistinguish:"",
        serialNumber:"",
      },
      loginRules: {
        username: [
          { required: true, trigger: "blur", message: "用户名不能为空" }
        ],
        password: [
          { required: true, trigger: "blur", message: "密码不能为空" }
        ],
        caPwd:[
          { required: true, trigger: "blur", message: "CA 密码不能为空" }
        ],
        slideStatus: { validator: validateSlide, trigger: 'change' }
        // code: [{ required: true, trigger: "change", message: "验证码不能为空" }]
      },
      loading: false,
      redirect: undefined,
      caOwner: '',
      systemName:'',
      certparams:{}
    };
  },
  watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect;
      },
      immediate: true
    }
  },
  created() {
    this.getCode();
    this.getCookie();
    // ca检测
    this.checkBrowser();
  },
  methods: {
    checkBrowser(){
      if (!!window.ActiveXObject || "ActiveXObject" in window){
        this.checkIeCa();
      }else{
        this.checkCA();
      }
    },
    checkIeCa(){
      let strpripath = "com1";
      let strcertpath = "com1";
      let strcertchainpath = "com1";
      let DevNumber = 41;//固定参数写死，无需修改
      SafeEngineCtl.ESE_InitialSession(DevNumber,strpripath, "", 0, DevNumber, strcertchainpath, "");
      if(SafeEngineCtl && SafeEngineCtl.ErrorCode && SafeEngineCtl.ErrorCode!==0 && SafeEngineCtl.ErrorCode!==-2113601477){
        this.$confirm(this.cetErrCode(SafeEngineCtl.ErrorCode), '提示', {
          confirmButtonText: 'Close',
          type: 'error',
          showCancelButton: false
        }).then(() => {
          SafeEngineCtl.ESE_ClearSession();
        }).catch(() => {
        });
      }
      SafeEngineCtl.ESE_ClearSession();
    },
    newCaSign(){
      if (!!window.ActiveXObject || "ActiveXObject" in window){
        this.ieCaInfoSign();
      }else{
        this.caInfoSign();
      }
    },
    ieCaInfoSign(){
      let strpripath = 'com1';
      let DevNumber = 41;//固定参数写死，无需修改
      if(!this.loginForm.caPwd){
        this.$message.error('CA 密码未输入!');
        this.loading = false;
        return false;
      }
      SafeEngineCtl.ESE_InitialSession(DevNumber,strpripath, this.loginForm.caPwd, 0, DevNumber, strpripath, "");
      if(SafeEngineCtl !== undefined && SafeEngineCtl.ErrorCode !== undefined && SafeEngineCtl.ErrorCode!==0 ){
        let errorCode = this.cetErrCode(SafeEngineCtl.ErrorCode);
        this.$confirm(errorCode, '提示', {
          confirmButtonText: 'Close',
          type: 'error',
          showCancelButton: false
        }).then(() => {
          SafeEngineCtl.ESE_ClearSession();
          this.loading = false;
        }).catch(() => {
        });
        return false;
      }
      console.log("SafeEngineCtl.ErrorCode:"+SafeEngineCtl.ErrorCode);
      //获取证书内容
      let strCert = SafeEngineCtl.ESE_GetSelfCertificate(DevNumber, strpripath);
      // 获取证书序列号
      let serialNumber = SafeEngineCtl.ESE_GetCertDetail(strCert,2);
      this.loginForm.serialNumber = serialNumber;
      let systemSign = SafeEngineCtl.ESE_GetCertInfoByOID(strCert,"1.2.156.1.8888.167");
      console.log("systemSign："+systemSign);
      if(!systemSign || (systemSign !== '上海注协'&& systemSign !=='涓婃捣娉ㄥ崗')){
        this.$confirm('您的ca不是本系统的!', '提示', {
          confirmButtonText: 'Close',
          type: 'error',
          showCancelButton: false
        }).then(() => {
          SafeEngineCtl.ESE_ClearSession();
          this.loading = false;
        }).catch(() => {
        });
        return false;
      }
      let serialNum = SafeEngineCtl.ESE_GetCertInfoByOID(strCert,"1.2.156.1.8888.148");
      if(serialNum&&serialNum.indexOf("XY")  !== -1){//事务所
        this.loginForm.onlyDistinguish = serialNum.substring(serialNum.indexOf("XY")+2);
      }else if(serialNum&&serialNum.indexOf("SF")!== -1){//身份证
        this.loginForm.onlyDistinguish = serialNum.substring(serialNum.indexOf("SF")+2);
      }else{
        this.$confirm('您的ca的唯一标识不正确', '提示', {
          confirmButtonText: 'Close',
          type: 'error',
          showCancelButton: false
        }).then(() => {
          this.loading = false;
        }).catch(() => {
        });
        return false;
      }
      let effectiveTime = SafeEngineCtl.ESE_GetCertValidDate(strCert);
      if(effectiveTime<30 && effectiveTime>0){
        this.$confirm( '您的证书还有'+effectiveTime+'天到期!', '提示', {
          distinguishCancelAndClose: true,
          confirmButtonText: '登录',
          closeOnPressEscape: false,
          closeOnHashChange: false,
          showClose: false,
          showCancelButton: false
        })
        .then(() => {
          this.signIeCa();
        })
        .catch(action => {
        });
      }else if(effectiveTime<=0){
        this.$confirm('您的证书已到期!', '提示', {
          confirmButtonText: 'Close',
          type: 'error',
          showCancelButton: false
        }).then(() => {
          this.loading = false;
        }).catch(() => {
        });
        return false;
      }else{
        this.signIeCa();
      }
    },
    signIeCa(){
      console.log("this.caPlaintext:"+this.caPlaintext);
      let strSigned = SafeEngineCtl.ESE_SignData(this.caPlaintext,'');
      if(SafeEngineCtl.ErrorCode !== 0){
        this.$confirm(this.cetErrCode(SafeEngineCtl.ErrorCode), '提示', {
          confirmButtonText: 'Close',
          type: 'error',
          showCancelButton: false
        }).then(() => {
        }).catch(() => {
        });
        SafeEngineCtl.ESE_ClearSession();
        return false;
      }
      this.loginForm.caSign = strSigned;
      this.login();
    },
    caInfoSign(){
      let that = this;
      let UkJsBridge = window.SheCaSDK.UkJsBridge;
      let Util = window.SheCaSDK.Util;
      UkJsBridge.getCert(this.certparams,that,Util).then(function(cert){
        that.certificate = cert;
        console.log(cert);
        let oidArray = ['1.2.156.1.8888.148'];
        oidArray = Util.certificateDecoder(cert.cert,oidArray);
        let oidNameArray = ['1.2.156.1.8888.167'];
        console.log(oidArray);
        oidNameArray = Util.certificateDecoder(cert.cert,oidNameArray);
        that.caOwner = oidArray.ownerInfo.value.CN;
        console.log(oidNameArray);
        //验证systemName上海注协
        let systemName = oidNameArray.extInfo['1.2.156.1.8888.167'].value;
        if(!systemName || systemName !== '上海注协'){
          that.$confirm('您的ca不是本系统的!', '提示', {
            confirmButtonText: 'Close',
            type: 'error',
            showCancelButton: false
          }).then(() => {
            that.loading = false;
          }).catch(() => {
          });
          return false;
        }
        //验证  唯一标识 与序列号存在
        let extinfovalue = oidArray.extInfo['1.2.156.1.8888.148'].value;
        console.log(extinfovalue)
        if(extinfovalue&&extinfovalue.indexOf("XY")  !== -1){//事务所
          //name 20191139 password 123456
          that.loginForm.onlyDistinguish = extinfovalue.substring(extinfovalue.indexOf("XY")+2);
        }else if(extinfovalue&&extinfovalue.indexOf("SF")!== -1){//身份证
          //name admin password admin123
          that.loginForm.onlyDistinguish = extinfovalue.substring(extinfovalue.indexOf("SF")+2);
        }else{
          that.$confirm('您的ca的唯一标识不正确', '提示', {
            confirmButtonText: 'Close',
            type: 'error',
            showCancelButton: false
          }).then(() => {
            that.loading = false;
          }).catch(() => {
          });
          return false;
        }
        let serialNumber = oidArray.sn.value;
        if( !serialNumber || serialNumber == '' ){
          that.$confirm('您的ca的usbkey不可用!', '提示', {
            confirmButtonText: 'Close',
            type: 'error',
            showCancelButton: false
          }).then(() => {
            that.loading = false;
          }).catch(() => {
          });
          return false;
        }else{
          that.loginForm.serialNumber = serialNumber;
        }
        let now = getDate();
        let expireTime = datedifference(now,oidArray.date.value.validEndDate.split(" ")[0]);
        if(expireTime<30 && expireTime>0){
          that.$confirm( '您的证书还有'+expireTime+'天到期!', '提示', {
            distinguishCancelAndClose: true,
            confirmButtonText: '登录',
            closeOnPressEscape: false,
            closeOnHashChange: false,
            showClose: false,
            showCancelButton: false
          })
          .then(() => {
            that.signCa();
          })
          .catch(action => {
          });
        }else if(expireTime<=0){
          that.$confirm('您的证书已到期!', '提示', {
            confirmButtonText: '关闭',
            type: 'error',
            showCancelButton: false
          }).then(() => {
            that.loading = false;
          }).catch(() => {
          });
        }else{
          that.signCa();
        }
      });
    },
    cetErrCode(errcode){
      switch (errcode) {
        case -2113601536 :
          return "读取文件错误(-2113601536)";
        case -2113601535 :
          return "密码错误(-2113601535)";
        case -2113601534 :
          return "非法句柄错误(-2113601534)";
        case -2113601533 :
          return "缺少ECC KEY错误(-2113601533)";
        case -2113601532 :
          return "ECC KEY 与算法不匹配错误(-2113601532)";
        case -2113601531 :
          return "非法算法错误(-2113601531)";
        case -2113601530 :
          return "数字签名错误(-2113601530)";
        case -2113601529 :
          return "摘要错误(-2113601529)";
        case -2113601528 :
          return "缓冲区太小(-2113601528)";
        case -2113601527 :
          return "证书格式错误(-2113601527)";
        case -2113601526 :
          return "缺少公钥错误(-2113601526)";
        case -2113601525 :
          return "验证签名错误(-2113601525)";
        case -2113601524 :
          return "产生公私钥对错误(-2113601524)";
        case -2113601523 :
          return "PKCS12编码错误(-2113601523)";
        case -2113601522 :
          return "PKCS12格式错误(-2113601522)";
        case -2113601520 :
          return "SE_ECC_ERROR_LOAD_BUILTIN_EC(-2113601520)";
        case -2113601519 :
          return "公私钥不匹配错误(-2113601519)";
        case -2113601518 :
          return "PKCS10编码错误(-2113601518)";
        case -2113601517 :
          return "PKCS10解码错误(-2113601517)";
        case -2113601516 :
          return "公钥格式错误(-2113601516)";
        case -2113601515 :
          return "PKCS10格式错误(-2113601515)";
        case -2113601514 :
          return "验证PKCS10错误(-2113601514)";
        case -2113601513 :
          return "ECC KEY格式错误(-2113601513)";

        case -2113601512 :
          return "公钥解码错误(-2113601512)";
        case -2113601511 :
          return "签名格式错误(-2113601511)";
        case -2113601510 :
          return "EC格式错误(-2113601510)";
        case -2113601509 :
          return "ECC KEY解码错误(-2113601509)";
        case -2113601508 :
          return "写入文件错误(-2113601508)";
        case -2113601507 :
          return "证书链非法错误(-2113601507)";
        case -2113601506 :
          return "内存分配错误(-2113601506)";
        case -2113601505 :
          return "初始化环境错误(-2113601505)";
        case -2113601504 :
          return "读取配置文件错误(-2113601504)";
        case -2113601503 :
          return "打开设备错误(-2113601503)";
        case -2113601502 :
          return "打开会话错误(-2113601502)";
        case -2113601501 :
          return "装载动态库错误(-2113601501)";
        case -2113601500 :
          return "设备类型错误(-2113601500)";
        case -2113601499 :
          return "算法不支持错误(-2113601499)";
        case -2113601498 :
          return "产生PKCS10错误(-2113601498)";
        case -2113601497 :
          return "导出公钥错误(-2113601497)";
        case -2113601496 :
          return "EC_POINT非法错误(-2113601496)";
        case -2113601495 :
          return "对称加密错误(-2113601495)";
        case -2113601494 :
          return "对称解密错误(-2113601494)";
        case -2113601493 :
          return "PEM解码错误(-2113601493)";
        case -2113601492 :
          return "获取证书细目错误(-2113601492)";
        case -2113601491 :
          return "PEM编码错误(-2113601491)";
        case -2113601490 :
          return "获取证书扩展项错误(-2113601490)";
        case -2113601489 :
          return "非法接口类型错误(-2113601489)";
        case -2113601488 :
          return "非法参数错误(-2113601488)";
        case -2113601487 :
          return "枚举设备错误(-2113601487)";
        case -2113601486 :
          // return "没有设备(-2113601486)";
          return "未插入UsbKey!";
        case -2113601485 :
          return "设备连接错误(-2113601485)";
        case -2113601484 :
          return "产生随机数错误(-2113601484)";
        case -2113601483 :
          return "SE_ECC_ERROR_SKF_SET_SYMKEY(-2113601483)";
        case -2113601482 :
          return "对称加密初始化错误(-2113601482)";
        case -2113601481 :
          return "对称加密错误(-2113601481)";
        case -2113601480 :
          return "设备管理员口令错误(-2113601480)";
        case -2113601479 :
          return "打开应用错误(-2113601479)";
        case -2113601478 :
          return "设备已锁(-2113601478)";
        case -2113601477 :
          return "设备口令错误(-2113601477)";
        case -2113601476 :
          return "枚举应用错误(-2113601476)";
        case -2113601475 :
          return "删除应用错误(-2113601475)";
        case -2113601474 :
          return "创建应用错误(-2113601474)";
        case -2113601473 :
          return "创建容器错误(-2113601473)";
        case -2113601472 :
          return "设备不支持错误(-2113601472)";
        case -2113601471 :
          return "打开容器错误(-2113601471)";
        case -2113601470 :
          return "导出公钥错误(-2113601470)";
        case -2113601466 :
          return "对称加密错误(-2113601466)";
        case -2113601465 :
          return "导入密钥对错误(-2113601465)";
        case -2113601464 :
          return "修改设备口令错误(-2113601464)";

        case -2113601463 :
          return "导入证书错误(-2113601463)";

        case -2113601462 :
          return "导出证书错误(-2113601462)";

        case -2113601461 :
          return "创建文件错误(-2113601461)";

        case -2113601460 :
          return "写入文件错误(-2113601460)";

        case -2113601459 :
          return "获取文件信息错误(-2113601459)";

        case -2113601458 :
          return "读取文件错误(-2113601458)";

        case -2113601457 :
          return "获取公钥错误(-2113601457)";
        case -2113601454 :
          return "生成密钥对错误(-2113601454)";
        case -2113601453 :
          return "证书已过期(-2113601453)";
        case -2113601452 :
          return "多个设备错误(-2113601452)";
        case -2113601451 :
          return "没有设备(-2113601451)";
        case -2113601450 :
          return "自动检测设备错误(-2113601450)";
        case -2113601449 :
          return "设备无法识别(-2113601449)";
        case -2113601448 :
          return "获取会话密钥错(-2113601448)";
        case -2113601447 :
          return "导入会话密钥错(-2113601447)";
        case -2113601446 :
          return "初始化摘要错误(-2113601446)";
        case -2113601445 :
          return "更新摘要错误(-2113601445)";
        case -2113601444 :
          return "生成会话密钥错(-2113601444)";
        case -2113601442 :
          return "导入会话密钥错(-2113601442)";
        case -2113601441 :
          return "缓冲区太小(-2113601441)";
        case -2113601440 :
          return "P7签名数据初始化错误(-2113601440)";
        case -2113601439 :
          return "产生随机数错误(-2113601439)";
        case -2113601438 :
          return "对称加密错误(-2113601438)";
        case -2113601437 :
          return "对称解密错误(-2113601437)";
        case -2113601436 :
          return "导出公钥错误(-2113601436)";
        case -2113601435 :
          return "添加p7算法错误(-2113601435)";
        case -2113601434 :
          return "P7数据处理错误(-2113601434)";
        case -2113601433 :
          return "SE_ECC_ERROR_ENVELOPE_ADD_RECIP(-2113601433)";
        case -2113601432 :
          return "签名数据错误(-2113601432)";
        case -2113601431 :
          return "摘要数据处理错误(-2113601431)";
        case -2113601430 :
          return "加密更新错误(-2113601430)";
        case -2113601429 :
          return "加密处理错误(-2113601429)";
        case -2113601428 :
          return "解密初始化错误(-2113601428)";
        case -2113601427 :
          return "解密更新错误(-2113601427)";
        case -2113601426 :
          return "解密处理错误(-2113601426)";
        case -2113601425 :
          return "p7格式错误(-2113601425)";

        case -2113601424 :
          return "SE_ECC_ERROR_P7_NO_RECIP(-2113601424)";

        case -2113601423 :
          return "算法非法(-2113601423)";

        case -2113601422 :
          return "私钥长度错误(-2113601422)";

        case -2113601421 :
          return "P7签名错误(-2113601421)";

        case -2113601420 :
          return "验证P7签名错误(-2113601420)";

        case -2113601419 :
          return "P7签名设置版本错误(-2113601419)";

        case -2113601418 :
          return "锁设备错误(-2113601418)";

        case -2113601417 :
          return "缓冲区太小(-2113601417)";

        case -2113601416 :
          return "从LDAP获取证书错误(-2113601416)";

        case -2113601415 :
          return "连接OCSP服务器错误(-2113601415)";

        case -2113601414 :
          return "参数错误(-2113601414)";

        case -2113601413 :
          return "CRL格式错误(-2113601413)";

        case -2113601412 :
          return "证书废除(-2113601412)";

        case -2113601411 :
          return "证书链格式错误(-2113601411)";

        case -2113601410 :
          return "验证证书链错误(-2113601410)";

        case -2113601409 :
          return "管理员密码错误(-2113601409)";

        case -2113601408 :
          return "设备标签格式错误(-2113601408)";

        case -2113601407 :
          return "删除容器错误(-2113601407)";

        case -2113601406 :
          return "枚举文件错误(-2113601406)";
        case -2113601405 :
          return "删除文件错误(-2113601405)";
        case -2113601404 :
          return "枚举容器错误(-2113601404)";
        case -2113601403 :
          return "关闭应用错误(-2113601403)";
        case -2113568768 :
          return "SE_ECC_ERROR_FUNC_LOCAL(-2113568768)";
        // 以下错误用于登录
        case -2113666824 :
          return "无效的登录凭证(-2113666824)";
        case -2113666823 :
          return "参数错误(-2113666823)";
        case -2113666822 :
          return "不是服务器证书(-2113666822)";
        case -2113666821 :
          return "登录错误(-2113666821)";
        case -2113666820 :
          return "证书验证方式错误(-2113666820)";
        case -2113666819 :
          return "随机数验证错误(-2113666819)";
        case -2113666818 :
          // return "与单点登录客户端代理通信(-2113666818)";
          return "电脑未安装协卡助手!";
      }
      return "其他";
    },
    checkCA(){
      let UkJsBridge = window.SheCaSDK.UkJsBridge;
      let that=this;
      UkJsBridge.getUkList(that).then(function(data){
        let list = data.list;
        let usb_key = list[0];
        that.usbKey = usb_key;
        that.certparams = {
          asymid:2, // asymid: 1 表示RSA算法，2：表示SM2算法
          usage:2, // usage: 1 表示加密 2: 表示签名
          devType:usb_key.devType,
          devParam:usb_key.devParam,
          keySN:usb_key.keySN,
        };
      }).catch(function(err){
        that.$confirm('USBKEY未插入,请先插入USBKEY后刷新页面!!', '提示', {
          confirmButtonText: 'Close',
          type: 'error',
          showCancelButton: false
        }).then(() => {
        }).catch(() => {
        });
      });
    },
    signCa(){
      let params = {
        data: this.caPlaintext , // 待签名的数据，string 类型
        pwd: this.loginForm.caPwd, // usb-key pin 码
        isHex: false, //是否是⼆进制数据(BASE64)，缺省:false
        algid: 3, //签名算法标识ID,缺省:3，3:SHA1withRSA算法；4:SHA256withRSA算法 5:SHA384withRSA算法 6:SHA512withRSA算法
        devType: this.certificate.devType, // 对应usb-key 的参数
        devParam: this.certificate.devParam, // 对应usb-key 的参数
        asymid: this.certificate.asymid, // 对应usb-key 的参数
        usage: this.certificate.usage // 对应usb-key 的参数
      };
      let UkJsBridge = window.SheCaSDK.UkJsBridge;
      let that = this;
      console.log("ca签名参数:");
      console.log(params);
      UkJsBridge.sign(params.data,params.pwd,params.isHex,params.algid,params.devType,params.devParam,params.asymid,params.usage,that).then(function (res) {
        console.log("ca签名结果:");
        console.log(res);
        if(res.data.ret === 0){
          that.loginForm.caSign = res.data.str;
         /* if(that.caOwner !== that.loginForm.username){
            that.$confirm('CA与该账号不匹配!', '提示', {
              confirmButtonText: 'Close',
              type: 'error',
              showCancelButton: false
            }).then(() => {
            }).catch(() => {
            });
            return false;
          }*/
          that.login();
        }else{
          that.$confirm('CA签名失败：'+ res.data.ret, '提示', {
            confirmButtonText: 'Close',
            type: 'error',
            showCancelButton: false
          }).then(() => {
          }).catch(() => {
          });
        }
      }).catch(function(err){
        that.$confirm('CA签名失败：'+ err, '提示', {
          confirmButtonText: 'Close',
          type: 'error',
          showCancelButton: false
        }).then(() => {
        }).catch(() => {
        });
      });
    },
    getCode() {
      // 干掉图片验证码
      // getCodeImg().then(res => {
      //   this.codeUrl = "data:image/gif;base64," + res.img;
      //   this.loginForm.uuid = res.uuid;
      // });
      getCaCode().then(res=>{
        this.caPlaintext = res.caRandomCode;
      });
    },
    getCookie() {
      const username = Cookies.get("username");
      const password = Cookies.get("password");
      const rememberMe = Cookies.get('rememberMe')
      this.loginForm = {
        username: username === undefined ? this.loginForm.username : username,
        password: password === undefined ? this.loginForm.password : decrypt(password),
        rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
      };
    },
    login(){
      this.loginForm.caPws="";
      this.$store
        .dispatch("Login", this.loginForm)
        .then(() => {
          this.$router.push({ path: this.redirect || "/" });
        })
        .catch(() => {
          this.loading = false;
          this.getCode();
        });
    },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true;
          if (this.loginForm.rememberMe) {
            Cookies.set("username", this.loginForm.username, { expires: 30 });
            Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
            Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
          } else {
            Cookies.remove("username");
            Cookies.remove("password");
            Cookies.remove('rememberMe');
          }
          // ca登录
           this.newCaSign();
          // 无ca登录
        // this.login();
        }
      });
    },
    /** 滑块验证 成功*/
    slideSuccess() {
      this.loginForm.slideStatus = true;
      this.$refs['loginForm'].clearValidate(['slideStatus']); // 清空校验
    },
    /** 滑块验证 失败*/
    slideError() {
      this.loginForm.slideStatus = false;
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  html{
    background-color:#fff !important;
  }
.login {
  min-height: 100vh;
  background-image: url("../assets/image/bg.png");
  background-size: cover;
}
.leftView{
  padding-top: 60px;
  max-width: 500px;
  min-height: 100vh;
  background: #fff;
}
.title {
  margin: 0 auto 10px auto;
  font-size: 20px;
  text-align: center;
  color: #004B9E;
  font-weight: 400;
}

.login-form {
  margin: 0 auto;
  width: 300px;
  border-radius: 6px;
  background: #ffffff;

  .el-input {
    height: 38px;
    input {
      height: 38px;
    }
  }
  .input-icon {
    height: 39px;
    width: 14px;
    margin-left: 2px;
  }
}
.login-tip {
  font-size: 13px;
  text-align: center;
  color: #bfbfbf;
}
.login-code {
  width: 33%;
  height: 38px;
  float: right;
  img {
    cursor: pointer;
    vertical-align: middle;
  }
}
.login-code-img {
  height: 38px;
}
.el-login-footer {
  margin:  0 auto;
  width: 300px;
  text-align: center;
  color: #555;
  font-size: 12px;
}
::v-deep .el-form-item.is-required:not(.is-no-asterisk)>.el-form-item__label:before {
  content: '';  // 去掉 * 号
  color: #ff4949;
  margin-right: 4px;
}
::v-deep .el-button--primary {
  color: #fff;
  background-color: #4164E3;
  border-color: #4164E3;
}
::v-deep .el-checkbox__input.is-checked+.el-checkbox__label {
  color: #5B79E7;
}
::v-deep .el-checkbox__input.is-checked .el-checkbox__inner {
  background-color: #5B79E7;
  border-color: #5B79E7;
}

</style>
